import 'package:flutter/material.dart';
import 'home.dart';
import 'cateroty.dart';
import 'cart.dart';
import 'member.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import '../provied/cartmodel.dart';
import 'package:provider/provider.dart';
import '../model/cartmodellist.dart';
class IndexPage extends StatefulWidget {
  
  //const IndexPage({Key key}) : super(key: key);
 
  @override
  // State<StatefulWidget> createState() {
  //   // TODO: implement createState
  //   throw UnimplementedError();
  // }
  _IndexPage createState()=>_IndexPage();
 
}
//with AutomaticKeepAliveClientMixin
class _IndexPage extends State<IndexPage>with AutomaticKeepAliveClientMixin {
  @override
  bool get wantKeepAlive => true;
   int indexTab=0;
  var cuer;
    final List<BottomNavigationBarItem> bootomtab = [
    BottomNavigationBarItem(icon: Icon(Icons.home), title: Text('首页')),
    BottomNavigationBarItem(icon: Icon(Icons.category), title: Text('分类')),
    BottomNavigationBarItem(icon: Icon(Icons.shopping_cart), title: Text('购物车')),
    BottomNavigationBarItem(icon: Icon(Icons.settings), title: Text('个人')),
  ];
  final List tablist=[
    HomePage(),
    CatePage(),
    CartPage(),
    MemberPage()
  ];
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
   // cuer=tablist[indexTab];
   setState(() {
       context.read<CartProvide>().getUsers();
        context.read<CartProvide>().getadminuser();
        context.read<CartProvide>().getOrder();
        getlist();
   });
  }
  @override
  Widget build(BuildContext context) {
    ScreenUtil.init(context, width: 750, height: 1334, allowFontScaling: false);
        return Scaffold(
      body: this.tablist[this.indexTab],
      bottomNavigationBar: BottomNavigationBar(
        currentIndex: indexTab,
        onTap:(int index){
          setState(() {
           this.indexTab=index;
          });
      },
        type: BottomNavigationBarType.fixed,
        items:bootomtab,
        fixedColor: Colors.orangeAccent,
      ),
    
    );
  }
  
}
//   final List<BottomNavigationBarItem> bootomtab = [
//     BottomNavigationBarItem(icon: Icon(Icons.home), title: Text('首页')),
//     BottomNavigationBarItem(icon: Icon(Icons.category), title: Text('首页')),
//     BottomNavigationBarItem(icon: Icon(Icons.shopping_cart), title: Text('首页')),
//     BottomNavigationBarItem(icon: Icon(Icons.settings), title: Text('首页')),
//   ];
//   final List tablist=[
//     HomePage(),
//     CartPage(),
//     CatePage(),
//     MemberPage()
//   ];
//   @override
//  void initState(){
//     super.initState();
//   }
//   Widget build(BuildContext context) {
//     return Scaffold(
//       appBar: AppBar(title: Text('主题颜色')),
//     );
//   }

